forum

home / developersection / forums / how to write super fast file streaming code in c#?

How to write super fast file streaming code in C#?

Anonymous User 3272 09-Feb-2014

I have to split huge file into many smaller files. each of the destination file is defined by offset and length as number of bytes. I'm using the following code:

 

private void copy(string srcFile, string dstFile, int offset, int length)

{

    BinaryReader reader = new BinaryReader(File.OpenRead(srcFile));

    reader.BaseStream.Seek(offset, SeekOrigin.Begin);

    byte[] buffer = reader.ReadBytes(length);

    BinaryWriter writer = new BinaryWriter(File.OpenWrite(dstFile));

    writer.Write(buffer);

}

Considering that I have to call this function about 100,000 times, it is remarkably slow.

 

Is there a way to make the Writer connected directly to the Reader? 


c# c# 
Updated on 09-Feb-2014

I am a content writter !


Message
Can you answer this question?

Answer

1 Answers

Liked By